import type {IColumnsOption} from 'vc';
import {
  INDEX,
  COMPANY_NAME,
  BUSINESS_DATA,
  REGISTERED_CAPITAL,
  PROVINCE,
  CITY,
  COUNTRY,
  INDUSTRY_CATEGORY
} from '@/utils/tableColumn';
import {setHrefUrlTool} from '@/utils';

export function useTable() {
  const columns = ref<IColumnsOption[]>([
    {...INDEX},
    {...COMPANY_NAME},
    {
      field: 'noticeDate',
      title: '披露日期',
      align: 'center',
      // sort: 'desc',
      sortable: true,
      width: 110,
      sortBy: 'noticeDate'
    },
    {
      width: 260,
      field: 'attachments',
      title: '信息来源',
      slots: {
        default: ({row}) => {
          return (
            <div>
              <a onClick={() => setHrefUrlTool(row.fileType, row.fileUrl)}>{row.tagName}</a>
              <br/>
            </div>
          );
        }
      }
    },
    {
      field: 'tagYear',
      title: '认定年度',
      align: 'center',
      sortable: true,
      width: 110,
      sortBy: 'tagYear',
      formatter({row, column}) {
        return row[column.field] ? row[column.field] + '年' : '-';
      }
    },
    {
      field: 'postLevel',
      title: '碳市场等级',
      align: 'center',
      sortable: true,
      sortBy: 'postLevel',
      width: 150,
    },
    {
      field: 'postAgency',
      title: '认定单位',
      align: 'center',
      sortable: true,
      sortBy: 'postAgency',
      width: 200
    },
    {...PROVINCE},
    {...CITY},
    {...INDUSTRY_CATEGORY},
    {...BUSINESS_DATA},
    {...REGISTERED_CAPITAL}
  ]);

  // 变更弹窗
  const showPermitChangesDetail = ref(false);
  const permitChangesDetails = ref([]);

  const permitChangesDetailFn = (data) => {
    console.log(data);
    showPermitChangesDetail.value = true;
    permitChangesDetails.value = data;
  };

  return {
    columns
  };
}
